<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html>
<html lang=it>

<head>
<title>Post: ${post.title }</title>
<meta charset="UTF-8">
<jsp:include page="partials/stylesheetChooser.jsp" />
</head>

<body>

	<jsp:include page="partials/header.jsp" />

	<div class="content">
		<div class="single-discussion">
			<div class="single-discussion--title">${post.title}</div>

			<div class="single--discussion--posts">
				<div class="post">
					<div class="post--info">
						<div class="post--info--username">${post.author.fullName}</div>
					</div>
					<div class="post--content">
						<div id="content${post.id}">${post.content}</div>
						<c:choose>
							<c:when test="${sessionScope.identity != null}">
							<!-- replyForm quando clicchi su quote va a fondo post -->
								<a href="#replyForm" onclick="quote(${post.id});">Quote</a>
							</c:when>
						</c:choose>
					</div>

				</div>
				<c:forEach var="response" items="${post.responses}"
					varStatus="status">
					<div class="post response">
						<div class="post--info">
							<div class="post--info--username">${response.author.fullName}</div>
						</div>
						<div class="post--content">
							<div id="content${status.index +1}">${response.content}</div>
							<c:choose>
								<c:when test="${sessionScope.identity != null}">
									<a href="#replyForm" onclick="quote(${status.index +1});">Quote</a>
								</c:when>
							</c:choose>
						</div>
					</div>
				</c:forEach>
			</div>
			<c:choose>
				<c:when test="${sessionScope.identity != null}">

					<a href="#replyForm" onclick="reply();">Rispondi</a>
					<form style="display: none" id="replyForm" name="input"
						method="post" class="single--discussion--reply"
						action="${pageContext.request.contextPath}/viewpost">
						<input type="hidden" name="postID" value="${post.id}" /> <label>Rispondi</label>
						<br>
						<textarea id="replyFormTextarea" name="response" rows="5"
							cols="80"></textarea>
						<input type="submit" value="Invia">
					</form>
				</c:when>
			</c:choose>
		</div>
	</div>



	<script type="text/javascript">

		function reply() {
			document.getElementById('replyForm').style.display = 'block';
		}
		function quote(id) {
			var quote = "[QUOTE]";
			quote += document.getElementById(("content").concat(id)).innerHTML;
			quote = quote.split("<blockquote class=\"quote\">").join("[QUOTE]");
			quote = quote.split("</blockquote>").join("[/QUOTE]");
			quote = quote.split("<br>").join("");
			quote += "[/QUOTE]";
			
			document.getElementById('replyFormTextarea').value += quote;
			reply();
		}
	</script>



</body>

</html>